package com.zhugang.week05;

/**
 * @program algorithms
 * @description: twoSum
 * @author: chanzhugang
 * @create: 2022/07/07 16:08
 */
public class TwoSum {

    /**
     * 1 两数之和
     *
     * @param nums
     * @param target
     * @return
     */
    public int[] twoSum(int[] nums, int target) {
        // 两层遍历，nums[i] + num[j] = target, 返回[i, j]
        for (int i = 0; i < nums.length - 1; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                if (nums[i] + nums[j] == target) {
                    return new int[]{i, j};
                }
            }
        }
        return new int[]{};
    }
}